<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>首页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/swiper.min.css">
    <link rel="stylesheet" href="../css/common.css"/>
    <link rel="stylesheet" href="../css/main.css"/>
</head>
<style type="text/css">
	 /*分享*/
        .shareimg img{
            position:absolute;
            top:0;
            right:0;
            z-index: 1;
        }
</style>
<body class="user_index">
<article>
    <section class="banner">
        <div class="swiper-container">
            <div class="swiper-wrapper" id="slide">
                <div class="swiper-slide"><img src="../img/test.png" style="width:100%;height: 4rem;" /></div>
                <div class="swiper-slide"><img src="../img/test.png" style="width:100%;height: 4rem;" /></div>
                <div class="swiper-slide"><img src="../img/test.png" style="width:100%;height: 4rem;" /></div>
            </div>
            <div class="swiper-pagination"></div>
        </div>
    </section>
    <section class="plr24 container">
        <div class="bw border-r1 ptb20 plr30 flex_sb shadow">
            <div class="flex_a avatar">
                <img src="../img/test.png" style="width:.86rem;height: .86rem;border-radius: 50%;">
                <span class="ml20"></span>
            </div>
            <div>
                <a class="link_btn bgc1 buy">购买纸巾</a>
                <a class="link_btn ml10 record">消费记录</a>
            </div>
        </div>
        <p class="lh80 col9">请选择你要关注的公众号</p>
        <ul class="bw border-r1 project clearfix">
            <!--<li class="item flex_aj tap">
                <img src="../img/none.png" class="project_img">
            </li>
            <li class="item flex_aj tap">
                <img src="../img/test1.png" class="project_img">
            </li>
            <li class="item flex_aj tap">
                <img src="../img/test1.png" class="project_img">
            </li>
            <li class="item flex_aj tap">
                <img src="../img/test1.png" class="project_img">
            </li>
            <li class="item flex_aj tap">
                <img src="../img/test1.png" class="project_img">
            </li>
            <li class="item flex_aj tap">
                <img src="../img/test1.png" class="project_img">
            </li>
            <li class="item flex_aj tap">
                <img src="../img/test1.png" class="project_img">
            </li>
            <li class="item flex_aj tap">
                <img src="../img/test1.png" class="project_img">
            </li>
            <li class="item flex_aj tap">
                <img src="../img/test1.png" class="project_img">
            </li>-->
        </ul>
        <!--<div class="bw border-r1 ptb30 flex_sb mt30 plr20" onclick="location.href='http://weixin.qq.com/r/DTkQCODEjb3yraRr92wf'">-->
        <div class="bw border-r1 ptb30 flex_sb mt30 plr20">
            <div>
                <!--<p>XXX纸巾机</p>-->
                <p class="address">地址:广东省东莞市ddddd</p>
            </div>
            <img src="../img/ico19.png" style="width: .46rem;" onclick="$('.shareimg').show()">
        </div>
    </section>
</article>
<article class="model_pane dpn qrcode">
    <section class="plr60 pt200">
        <div class="border-r1 bw tac pt80 pb40 pos_r">
            <p class="freeCode"></p>
            <div id="qrcode" class="mb20 mt40">
            	<!--<img src="../img/test2.png" style="width:3rem;height: 3rem;" class="mt40">-->
            </div>
            <p class="mt20 name"></p>
            <div class="model_close font21 col9 tap" onclick="$('.model_pane').hide();$('#qrcode').children().remove()">&times;</div>
        </div>
    </section>
</article>
<article class="model_pane dpn" id="adv">
    <section class="plr100 pt200">
        <div class="border-r1 bw tac pos_r adv">
            <!--<img src="../img/test.png" class="pw100">
            <p class="p20">迪尔西</p>-->
        </div>
    </section>
    <div class="mt100 tac"  onclick="$('.model_pane').hide()">
        <img src="../img/ico20.png" style="width: .5rem;height: .5rem;">
    </div>
</article>

<!--分享-->
	<div class="shareimg dpn" style="position: fixed;width: 100%;height: 100%;background: rgba(0,0,0,.5);z-index: 2;top: 0;left: 0;">
		<img src="../img/shareImg.png" style="width:2.5rem;height:2.5rem;"/>
	</div>
    

</body>
</html>
<script src="../js/jquery-1.8.3.min.js"></script>
<script src="../js/swiper-3.4.1.min.js"></script>
<script src="../js/jquery-qrcode-0.14.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/dlc.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
<script>
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        slidesPerView: 1,
        paginationClickable: true,
        spaceBetween: 30,
        autoplay: 3000,
        autoplayDisableOnInteraction: false, //falase,用户操作后，定时滑动
        loop: true
    });
    
    var openid;
    
if(!user_openid() && getUrlParam('code')){
   // dlc_request('/api/h5/getOpenId',{'code':getUrlParam('code')},function(res){
        //console.log(res);
//      if(res.code == 1){
//          openid_save(res.data.openId)
//			dlc_request('/api/h5/getUserInfo',{'openId':res.data.openId},function(res1){
//		        console.log(res1);
//		        if(res1.code==1){
//		        	$('.avatar img').attr('src',res1.data.headImgUrl)
//		        	$('.avatar span').text(res1.data.name)
//		        }
//		    });
//		    
//		    wx_list(res.data.openId)//获取公众号列表
//		    
//      }else{
//      	
//      }          
    //},false);
}else if(user_openid()){
		openid = user_openid()
			dlc_request('/api/h5/getUserInfo',{'openId':openid},function(res1){
		        console.log(res1);
		        if(res1.code==1){
		        	$('.avatar img').attr('src',res1.data.headImgUrl)
		        	$('.avatar span').text(res1.data.name)
		        }
		    },false);
		    

		    wx_list(user_openid())//获取公众号列表
		    
}



$('.buy').click(function(){
	location.href='user_pay.html?deviceNo='+getUrlParam('deviceNo').split(',')[0]+'&imei='+getUrlParam('deviceNo').split(',')[1]+'&openid='+openid
})

$('.record').click(function(){
	location.href='user_record_buy.html?deviceNo='+getUrlParam('deviceNo').split(',')[0]
})

//
//dlc_request('/api/h5/showAdv',{},function(ret){
//  console.log(ret);
//  $('.adv').append('<img src="'+location.origin+ret.data.imgUrl+'" class="pw100">')
//  $('#adv').show()
//});











function wx_list(openid){
	dlc_request('/api/h5/getUserOfficialList',{deviceNo:getUrlParam('deviceNo').split(',')[0],'openId':openid},function(ret){
	    console.log(ret);
	    for(i in ret.data.wx_public){
	    	$('.project').append('<li class="item flex_aj tap" data-id="'+ret.data.wx_public[i].id+'"  data-is_null="'+ret.data.wx_public[i].is_null+'"><img src="'+(ret.data.wx_public[i].is_null==1?location.origin+ret.data.wx_public[i].imgUrl:'../img/none.png')+'" class="project_img"></li>')
	    }
	    $('.address').text('地址:'+ret.data.addressDetail)
	});
}



$('.project').on('click','.item',function(){
	if($(this).data('is_null')!='undefined'){
		dlc_request('/api/h5/getUserOfficialInfo',{'openid':openid,id:$(this).data('id'),imei:getUrlParam('deviceNo').split(',')[1],deivceNo:getUrlParam('deviceNo').split(',')[0]},function(res){
		    console.log(res);
		    if(res.code==1){
		    	$('#qrcode').qrcode({
					render: "image",
					size: 150,
					text: res.data.url
				});
		    	$('.qrcode .freeCode').text('长按二维码关注后回复'+res.data.freeCode)
		    	$('.qrcode .name').text(res.data.name)
		    	$('.qrcode').show()
		    }else{
		    	dlctipbox.show(res.msg)
		    }
		});
	
	}	
})








            dlc_request('/wx/getTicket',{},function(res){
            console.log(res);
                var timestamp=(new Date().getTime()/1000).toFixed(0);
				var nonceStr=Math.random().toString(36).substr(2);
				var ticket=wx_js(res.ticket,timestamp,nonceStr);
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端//alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: 'wx2c49fec17dc24b80', // 必填，公众号的唯一标识
                    timestamp: timestamp, // 必填，生成签名的时间戳
                    nonceStr:  nonceStr, // 必填，生成签名的随机串
                    signature:ticket ,// 必填，签名，见附录1
                    jsApiList: ['checkJsApi',
                        'onMenuShareTimeline',
                        'onMenuShareAppMessage',
                        'onMenuShareQQ',
                        'onMenuShareWeibo',
                        'hideMenuItems',
                        'showMenuItems',
                        'hideAllNonBaseMenuItem',
                        'showAllNonBaseMenuItem',
                        'translateVoice',
                        'startRecord',
                        'stopRecord',
                        'onRecordEnd',
                        'playVoice',
                        'pauseVoice',
                        'stopVoice',
                        'uploadVoice',
                        'downloadVoice',
                        'chooseImage',
                        'previewImage',
                        'uploadImage',
                        'downloadImage',
                        'getNetworkType',
                        'openLocation',
                        'getLocation',
                        'hideOptionMenu',
                        'showOptionMenu',
                        'closeWindow',
                        'scanQRCode',
                        'chooseWXPay',
                        'openProductSpecificView',
                        'addCard',
                        'chooseCard',
                        'openCard'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                });

                        wx.ready(function () {
                            // 2. 分享接口
                            // 2.1 监听“分享给朋友”，按钮点击、自定义分享内容及分享结果接口
                                wx.onMenuShareAppMessage({
                                    title: '个联纸巾机',
                                    desc: '个联共享纸巾机，每天免费领取',
                                    link: 'gxzjj.j.xiaozhuschool.com/h5/gxzjj/other/html/user_index.html?deviceNo=20180713111222,zc5b47124a95f8f',
                                    imgUrl: 'gxzjj.j.xiaozhuschool.com/h5/gxzjj/other/img/logo.png',
                                    trigger: function (res) {
                                        // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
                                        //      alert('用户点击发送给朋友');
                                        console.log(res)
                                    },
                                    success: function (res) {
                                        // alert('已分享');
                                        dlctipbox.show('已分享')
										$('.shareimg').hide()
                                    },
                                    cancel: function (res) {
                                         dlctipbox.show('已取消')
                                    },
                                    fail: function (res) {
                                        // alert(JSON.stringify(res));
                                        dlctipbox.show('分享失败')
                                    }
                                });
                        })

    

            });


</script>






















